<%@ taglib uri="/WEB-INF/displaytag-12.tld" prefix="display" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>


<%
	session.setAttribute("back", "search");
%>
<script>
function changeStatus()
{
	debugger;
	if(document.getElementById('listPict').checked) {
		document.getElementById('listPict').value = "on";
	} else {
		document.getElementById('listPict').value = "off";
	}

}
</script>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<jsp:include page="/jsp/top.jsp" />
<table width="720" border="0" align="center" cellpadding="0" cellspacing="0">
 
  <tr>
    <td><table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="183" valign="top" rowspan="2">
      <form action="../portal/SearchAdv.do?action=SearchAd">
        <input type="hidden" name="PostingType" value="99"/>
        </form>
      <br>
    </td>
    <td width="5" height="256"></td>
    <td width="928" valign="top">
    <%
		String choice = request.getParameter("Action");
		if (choice!=null && choice.equals("Search")) {

			String postingType = request.getParameter("PostingType");
			request.setAttribute("category_id",postingType);
			String catType = request.getParameter("CatType");
			String location = request.getParameter("Location");
			String place = request.getParameter("Place");
			String adContent = request.getParameter("adContent");
			String pricemin = request.getParameter("pricemin");
			String pricemax = request.getParameter("pricemax");
	%>
      <jsp:forward page="../portal/SearchAdv.do?action=SearchAd"/>
    <%
    	} else if (choice!=null && choice.equals("Cancel")) {
	%>
      <jsp:forward page="../portal/index.do"/>
    <%
    	}
    %>
      <!--test-->
      <%

java.sql.Connection conn = null;
java.sql.Statement  stat = null;
javax.naming.InitialContext context = new javax.naming.InitialContext();
//javax.sql.DataSource ds = (javax.sql.DataSource)context.lookup("java:comp/env/jdbc/portalDB");
Class.forName( "com.mysql.jdbc.Driver");
conn = java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/ba3602_classifiedsdb", "root", "test");
stat = conn.createStatement();

%>
      <form name="form1" method="post" action="../jsp/SearchClassifieds.jsp">
        <table width="1000" border="0" cellpadding="2" cellspacing="2">
          <tr>
            <td valign="top" height="22" colspan="4" class="title bluehead">Search Classifieds:<br />
			<img src="../images/line.jpg" width="1000" /></td>
            </tr>
          <tr>
            <td width="185" height="0"></td>
            <td width="230"></td>
            <td width="74"></td>
            <td width="403"></td>
          </tr>
          <tr>
            <td align="right" valign="top" class="text">Posting Type:</td>
            <td colspan="3" valign="top">
              <select name="PostingType" onChange="javascript:submit()" class="field">
                <option value="99">All</option>
                <%
		  //if (request.getParameter("PostingType")==null){
		  	java.sql.ResultSet rs = stat.executeQuery("select name,category_id  from categories where par_category_id is null;");

			String postingType = request.getParameter("PostingType");
			int postingID=0;
			if (postingType!=null && postingType.length()>0){
			 postingID = Integer.parseInt(postingType);
			} else {
			%>
                <option value="99" selected>--Select a Category--</option>
                <%}
			while (rs.next()){
			String name = rs.getString(1);
			int id = rs.getInt(2);
		  %>
                <%
				if (id==postingID )
				{
				out.println(name +"  "+postingType);
			%>
                <option value="<%=id%>" selected><%=name%></option>
                <%} else {%>
                <option value="<%=id%>"><%=name%></option>
                <%
			}} //rs.close();
	   //	stat.close();
			%>
              </select>
            </td>
            </tr>
          <tr>
            <td align="right" valign="top" class="text">Sub Category Type:</td>
            <td colspan="3" valign="top">
              <% if (postingID==0)
         {%>
              <select name="CatType" onChange="javascript:submit()" disabled='true' class="field">
                <option value="0">All</option>
                <%}%>
                <% if (postingID!=0 || postingID==99)
		   {%><select name="CatType" onChange="javascript:submit()" class="field">
                <option value="0">All</option>
                <%
		   	 rs = stat.executeQuery("select name,category_id  from categories where par_category_id ="+postingID);
			 String subcategory_id = request.getParameter("CatType");
			int subidCat=0;
			if (subcategory_id!=null && subcategory_id.length()>0){
			 subidCat = Integer.parseInt(subcategory_id);
			}
			 while (rs.next()){
			 String subname = rs.getString(1);
			 int subid = rs.getInt(2);

		   %>
                <%
				if (subid==subidCat )
				{
				//out.println(name +"  "+postingType);
			%>
                <option value="<%=subid%>" selected><%=subname%></option>
                <%} else {%>
                <option value="<%=subid%>"><%=subname%></option>
                <%
			}}}	%>
              </select>
            </td>
            </tr>
          <tr>
            <td align="right" valign="top" class="text">Location:</td>
            <td valign="top">
              <% if (postingID==0)
         {%>
              <select name="Location" onChange="javascript:submit()" disabled='true' class="field">
                <%}%>
                <% if (postingID!=0)
		   {%><select name="Location" onChange="javascript:submit()" class="field">
                <%}%>
                <%
		  	String loc = request.getParameter("Location");
		  	if (loc==null)
		  	{
		  %>
                <option value="0">All</option>
                <option value="1">Central Pune</option>
                <option value="2">East Pune</option>
                <option value="3">West Pune</option>
                <option value="4">South Pune</option>
                <option value="5">Suburban</option>
                <%}%>
				 <%	if (loc!=null) { if (loc.equals("0") && postingID!=0){%>
				 	 <option value="0">All</option>
					                <option value="1">Central Pune</option>
					                <option value="2">East Pune</option>
					                <option value="3">West Pune</option>
					                <option value="4">South Pune</option>
                <option value="5">Suburban</option>
				 <%}}%>
                <%	if (loc!=null && loc.length()>0)
			{
			int locid = Integer.parseInt(loc);

		  %>
                <% if (locid==1) {%>
                 <option value="0">All</option>
		                <option value="1" selected>Central Pune</option>
		                <option value="2">East Pune</option>
		                <option value="3">West Pune</option>
		                <option value="4">South Pune</option>
                <option value="5">Suburban</option>
                <%}%>
                <% if (locid==2) {%>
                 <option value="0">All</option>
		                <option value="1">Central Pune</option>
		                <option value="2" selected>East Pune</option>
		                <option value="3">West Pune</option>
		                <option value="4">South Pune</option>
                <option value="5">Suburban</option>
                <%}%>
                <% if (locid==3) {%>
                <option value="0">All</option>
	                       <option value="1">Central Pune</option>
	                       <option value="2">East Pune</option>
	                       <option value="3" selected>West Pune</option>
	                       <option value="4">South Pune</option>
                <option value="5">Suburban</option>
                <%}%>
                <% if (locid==4) {%>
               <option value="0">All</option>
	                      <option value="1">Central Pune</option>
	                      <option value="2">East Pune</option>
	                      <option value="3">West Pune</option>
	                      <option value="4" selected>South Pune</option>
                <option value="5">Suburban</option>
                <%}%>
                <% if (locid==5) {%>
                <option value="0">All</option>
	                       <option value="1">Central Pune</option>
	                       <option value="2">East Pune</option>
	                       <option value="3">West Pune</option>
	                       <option value="4">South Pune</option>
                <option value="5" selected>Suburban</option>
                <%}%>
                <%}%>
              </select>
            </td>
            <td valign="top" class="text">Place</td>
            <td>
              <select name="Place" class="field">
                <option value="0">All</option>
                <%
			  		String location = request.getParameter("Location");
			  		if (location!=null && location.length()>0) {
			  			int locid = Integer.parseInt(location);
		   	 			rs = stat.executeQuery("select name,area_id  from lookup_area where par_category_id ="+locid);
			 			while (rs.next()){
			 				String locname = rs.getString(1);
			 				int locID = rs.getInt(2);
		   					if (locid==locID || String.valueOf(locID).equals(request.getParameter("Place"))) {
								//out.println(name +"  "+postingType);
				%>
                				<option value="<%=locID%>" selected><%=locname%></option>
                <%
                			} else {
                %>
                				<option value="<%=locID%>"><%=locname%></option>
                <%
                			}
                		}
                	}
                %>
              </select>
            </td>
          </tr>
          <tr>
            <td align="right" class="text"></td>
            <td></td>
            <td></td>
            <td></td>
          </tr>
          <tr>
            <td align="right" class="text">Search Query </td>
            <td colspan="3">
              <input type="text" name="adContent" maxlength="" value="<%=request.getParameter("adContent")==null?"":request.getParameter("adContent")%>" size="50">
            </td>
            </tr>
           <tr>
	              <td align="right" class="text">Exclude words<br>                  </td>
	              <td colspan="3">
	                <input type="text" name="excludeSearchContent" value="<%=request.getParameter("excludeSearchContent")==null?"":request.getParameter("excludeSearchContent")%>" size="50">
	              </td>
           </tr>
		  <% String pt = request.getParameter("PostingType");
		  if (pt!=null){
		  if (request.getParameter("PostingType").equals("1") || request.getParameter("PostingType").equals("2"))
		  {%>

          <tr>
            <td align="right" class="text">Price Min</td>
            <td colspan="3">
              <input type="text" name="pricemin" value="<%=request.getParameter("pricemin")==null?"":request.getParameter("pricemin")%>" size="" >
            </td>
            </tr>
          <tr>
            <td align="right" class="text">Price Max</td>
            <td colspan="3">
              <input type="text" name="pricemax" maxlength="" value="<%=request.getParameter("pricemax")==null?"":request.getParameter("pricemax")%>" size="">
            </td>
            </tr><%}}%>
		  <tr>
		  <td align="right" class="text">Listings With Pics</td>
			<td class="text">
				<%
					if("on".equals(request.getParameter("listPict"))) {
				%>
					<input type="checkbox" checked name="listPict" onClick="javascript:changeStatus()">
				<%
					} else {
				%>
					<input type="checkbox" name="listPict" onClick="javascript:changeStatus()">
				<%
					}
				%>
			</td>
		  </tr>
          <tr>
            <td colspan="4" align="center">
              <input name="Action" type="image" src="../images/submit.jpg" class="button" value="Search"  >
              <input name="Action" type="image" class="button" src="../images/cancel.jpg" value="Cancel">
            </td>
         </tr>
        </table>
      </form>
      <%conn.close();%>
    </td>
    <td width="31"></td>
  </tr>

</table> </td>
  </tr>
<tr><td><br /><br /><br /><br /><br /><br /> <jsp:include page="footer.html"/> </td></tr>
</table>
 <br>
 <br>

<jsp:include page="map.html"/>
</body>
</html>
